package org.grow.mvcpractise.filter;

import org.springframework.stereotype.Service;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class SecondFilter implements Filter {

    private AtomicInteger countPerson = new AtomicInteger(0);

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("%%%%%%%%%%%%%%我是二楼");

        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

//        权限拦截
//        统计
//        增强request
        String requestURI = httpServletRequest.getRequestURI();

        if (requestURI.contains("person")){
             countPerson.incrementAndGet();

        }
        System.out.println("目前 personXXX请求访问总次数: "+countPerson.get());

        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("%%%%%%%%%%%%%%我是二楼　倒序");
    }
}
